home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qb_trap.zip / QB-TRAP.ASM
Assembly Source File  |  1991-09-06  |  1KB  |  33 lines

  1. ;********** TrapInt.Asm - returns a value "trapped" within a specified range
  2.  
  3. ;Copyright (c) 1989 Ethan Winer
  4.  
  5. ;Syntax - LOCATE TrapInt%(Y%, 1, 25), TrapInt%(X%, 1, 80)
  6.  
  7.  
  8. .Model Medium
  9. .Code
  10.     Include Mixed.Inc
  11.  
  12. HProc TrapInt, Value:Ptr, Min:Ptr, Max:Ptr
  13.  
  14.     Mov  SI,Value         ;get the address for Value
  15.     Mov  AX,[SI]          ;put it in AX assuming it is within range
  16.     Mov  SI,Min           ;get the address for the minimum acceptable value
  17.     Cmp  AX,[SI]          ;see if AX is indeed equal or larger
  18.     Jge  CheckMax         ;it is, now check if it's within the upper limit
  19.     Mov  AX,[SI]          ;out of range, so assign it to the minimum
  20.     Jmp  Short Exit       ;and skip the remaining test
  21.  
  22. CheckMax:
  23.     Mov  SI,Max           ;get the address for the maximum acceptable value
  24.     Cmp  AX,[SI]          ;see if AX is within the upper limit
  25.     Jle  Exit             ;yes, exit with the incoming value as the result
  26.     Mov  AX,[SI]          ;no, assign AX to the maximum limit
  27.  
  28. Exit:
  29.     HRet                  ;return to BASIC with the function output in AX
  30.  
  31. HEndp
  32. End
  33.